package com.karina.visualization.chart.component;

import java.util.List;

import com.karina.visualization.chart.model.ShapeModel;

public class TweenEffectPlayer {

	public final static int DEFAULT_EFFECTION_DURATION = 1000;

	public final static int DEFAULT_FRAME = 50;

	private final ChartObject<ShapeModel<?>, ?> chart;

	private int current_steps = 0;

	@SuppressWarnings("rawtypes")
	private final ShapeModel src;
	@SuppressWarnings("rawtypes")
	private final ShapeModel target;

	@SuppressWarnings("rawtypes")
	private List<ShapeModel> models;

	private int steps;

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public TweenEffectPlayer(ChartObject chartObject, ShapeModel src,
			ShapeModel target) {
		this.chart = chartObject;
		this.src = src;

		this.target = target;
	}

	@SuppressWarnings("unchecked")
	public void play(int steps) {
		if (src == null)
			return;

		this.setSteps(steps);

		models = src.createSeriesModelSteps(target, steps);
		current_steps = 0;

		chart.getUpdateManager().disable();
	}

	public boolean nextStep() {
		if (models == null || models.size() == 0)
			return true;

		if (models.size() > current_steps) {
			chart.setData(models.get(current_steps));
		}
		chart.update();
		current_steps++;
		if (current_steps == models.size()) {
			// chart.getUpdateManager().enable();
			return false;
		}

		return true;
	}

	public void setSteps(int steps) {
		this.steps = steps;
	}

	public int getSteps() {
		return steps;
	}
}
